package com.yunhe.abnormal.service.base.impl;

import com.yunhe.abnormal.domain.base.AlarmNotifyType;
import com.yunhe.abnormal.mapper.base.AlarmNotifyTypeMapper;
import com.yunhe.common.model.base.AlarmNotifyTypeDTO;
import com.yunhe.abnormal.repository.base.AlarmNotifyTypeRepository;
import com.yunhe.abnormal.service.base.AlarmNotifyTypeService;
import com.yunhe.common.util.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 异常通知类型Service
 * @author liuronglei
 */
@Service
public class AlarmNotifyTypeServiceImpl implements AlarmNotifyTypeService {
    @Autowired
    private AlarmNotifyTypeRepository alarmNotifyTypeRepository;
    @Autowired
    private AlarmNotifyTypeMapper alarmNotifyTypeMapper;

    /**
     * 根据ID获得异常通知类型对象
     * @param id 状态ID
     */
    public AlarmNotifyTypeDTO findById(Long id) {
        AlarmNotifyType result = alarmNotifyTypeRepository.findById(id).orElse(null);
        return alarmNotifyTypeMapper.to(result);
    }

    /**
     * 根据编号获得异常通知类型对象
     * @param name 编号
     */
    public AlarmNotifyTypeDTO findByName(String name) {
        AlarmNotifyType result = alarmNotifyTypeRepository.findByName(name);
        return alarmNotifyTypeMapper.to(result);
    }

    /**
     * 获得全部异常通知类型对象
     */
    public List<AlarmNotifyTypeDTO> findAll() {
        List<AlarmNotifyType> results = (List<AlarmNotifyType>) alarmNotifyTypeRepository.findAll(QueryUtil.defaultSort());
        return alarmNotifyTypeMapper.to(results);
    }

}
